﻿Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX
Public Class ObjektCheckBox
    Inherits Objekt2D


    Dim Checkeds As Boolean = False
    Public Property Checked() As Boolean
        Get
            Return Checkeds
        End Get
        Set(ByVal value As Boolean)
            Checkeds = value
        End Set
    End Property
    Dim Geklickt As Boolean = False
    Public Sub New(ByVal Position As Point, ByVal Bild As String, ByVal Fixed As PointF, Optional ByVal Checked As Boolean = True, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New(Bild, New Rectangle(0, 0, 18, 18), Position, Fixed, Handler)
        Me.Checked = Checked
    End Sub

    Public Overloads Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble() Then
            If (Not HasFocus) Or Focused Then
                Dim P As Point = GetRealKoordinaten()
                If New Rectangle(P.X, P.Y, Rechteck.Width, Rechteck.Height).Contains(e.Location) Then
                    Geklickt = True
                End If
            End If
        End If
    End Function

    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        If IsVisble() Then
            If (Not HasFocus) Or Focused Then
                Dim P As Point = GetRealKoordinaten()
                If New Rectangle(P.X, P.Y, Rechteck.Width, Rechteck.Height).Contains(e.Location) Then
                    If Geklickt = True Then
                        MusikEngine.LoadWav(DataSettings.Resourcenpfad + "Sound\Sound Effects\System\Checkbox.wav", False)
                        Checked = Not Checked
                        Geklickt = False
                    End If
                    Return "Geklickt"
                Else
                    Geklickt = False
                    Return ""
                End If
            Else
                Geklickt = False
                Return ""
            End If
        Else
            Return ""
        End If
    End Function
    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If
        MyBase.Malen()
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        If Checked = True Then
            With Grafikengine.recBild
                .X = 0 : .Width = 18
                .Y = 0 : .Height = 18
            End With
        Else
            With Grafikengine.recBild
                .X = 18 : .Width = 18
                .Y = 0 : .Height = 18
            End With
        End If
        With Grafikengine.szfScale
            .Height = 18
            .Width = 18
        End With
        Grafikengine.ptfPosition = GetRealKoordinaten()
        Grafikengine.ptfRotCenter = New Point
        Grafikengine.Sprite.Draw2D(TexturenHalter.GetKreuzHakenTextur, Grafikengine.recBild, Grafikengine.szfScale, Grafikengine.ptfRotCenter, sngRotation, Grafikengine.ptfPosition, intColor)
    End Sub

    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function
End Class
Public Class ObjektKOCheckBox
    Inherits ObjektCheckBox
    Dim KO As Integer
    Public Function GetKO() As ObjektKO
        Return ObjektLadeklasse.NewKO(Objektverwalter.GetKO(KO).KOID, 0)
    End Function
    Dim Pos As Point
    Public Sub New(ByVal Position As Point, ByVal Bild As String, ByVal KOID As Integer, ByVal Fixed As PointF, Optional ByVal Checked As Boolean = True, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New(New Point(Position.X + 15, Position.Y + 53), Bild, Fixed, Checked, Handler)
        Me.KO = KOID
        Pos = Position
    End Sub
    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        If IsVisble() Then
            Return MyBase.MouseDown(sender, e)
        End If
    End Function
    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        If IsVisble() Then
            Return MyBase.MouseUp(sender, e)
        Else
            Return ""
        End If
    End Function
    Public Overrides Sub Malen()
        If IsVisble() Then
            Dim P As Point = GetRealKoordinaten()
            Objektverwalter.GetKO(KO).KOGesichtsausdruckMalen(0, P.X - 15, P.Y - 53)
            MyBase.Malen()
        End If
    End Sub
    Public Sub ChangePosition(ByVal NeuPos As Point)
        Pos = NeuPos
        Koordinatene.X = NeuPos.X + 15
        Koordinatene.Y = NeuPos.Y + 53
    End Sub
    Protected Overrides Function IsVisble(Optional ByVal PlusX As Integer = 0, Optional ByVal PlusY As Integer = 0) As Boolean
        If Handler IsNot Nothing Then
            If Handler.IsVisible(New Rectangle(Koordinaten.X - 15, Koordinaten.Y - 53, Rechteck.Width + PlusX + 15, Rechteck.Height + PlusY + 53), True) Then
                Return True
            Else
                Return False
            End If
        Else
            Return True
        End If
    End Function
End Class
Public Class ObjektEinheitenUserData
    Inherits Objekt2D

    Dim Unit As Integer
    Dim Value As Integer = 0
    Dim Farbe As Color
    Dim Spieler As ObjektSpieler
    Dim Frames As Integer = 0
    Dim Text As ObjektText

    Public Property Framer() As Integer
        Get
            Return Frames / 2
        End Get
        Set(ByVal value As Integer)
            Frames += 1
            If Frames > 6 Then
                Frames = 0
            End If
        End Set
    End Property
    Public Sub New(ByVal Position As Point, ByVal Fixed As PointF, ByVal UnitID As String, ByVal Build As Boolean, ByVal Farbe As Color, Optional ByVal Handler As ObjektPanel = Nothing)
        MyBase.New("", New Rectangle(0, 0, 18, 18), Position, Fixed, Handler)
        Me.Farbe = Farbe
        Spieler = New ObjektSpieler(1, Farbe, 0, Nothing, 0, Armeen.OS.ToString, "A", Nothing, ObjektSpieler.KIStufen.Geschlossen, 0)
        For I = 0 To Objektverwalter.AlleEinheiten.Length - 1
            If Objektverwalter.AlleEinheiten(I).EinheitenID = UnitID Then
                Unit = I
                Exit For
            End If
        Next
        If Build Then
            For I = 0 To Hauptmenue.User.BuildUnits.Count - 1
                If Hauptmenue.User.BuildUnits(I).UnitID = UnitID Then
                    Value = Hauptmenue.User.BuildUnits(I).Counter
                    Exit For
                End If
            Next
        Else
            For I = 0 To Hauptmenue.User.DestroyedUnits.Count - 1
                If Hauptmenue.User.DestroyedUnits(I).UnitID = UnitID Then
                    Value = Hauptmenue.User.DestroyedUnits(I).Counter
                    Exit For
                End If
            Next
        End If
        If Build Then
            Text = New ObjektText(New String() {Value.ToString}, 20, 1, New Color() {Color.Green}, Schriftengine.Schriftarten.Arial, 14, FontStyle.Regular)
        Else
            Text = New ObjektText(New String() {Value.ToString}, 20, 1, New Color() {Color.Red}, Schriftengine.Schriftarten.Arial, 14, FontStyle.Regular)
        End If

        Bildgroesse.Width += Text.GetFontDimension(0).Width
    End Sub

    Public Overloads Overrides Function Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean
        'Nothing
    End Function

    Public Overloads Overrides Function MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As String
        Return ""
    End Function
    Public Overrides Sub Malen()
        If Handler IsNot Nothing Then
            If Not Handler.IsVisible(New Rectangle(Koordinaten.X, Koordinaten.Y, Rechteck.Width, Rechteck.Height), True) Then
                Exit Sub
            End If
        End If
        Dim sngRotation As Double = 0
        Dim intColor As Color = Color.FromArgb(255, 255, 255, 255)
        Grafikengine.ptfPosition = GetRealKoordinaten()

        If DataSettings.CommanderWarsGameModus = CommanderWarsGameModi.FireEmblem Then
            Dim FireEmblemUnit As Fire_Emblem_MOD.FEUnit = Objektverwalter.AlleEinheiten(Unit).Einheit
            With Grafikengine.recBild
                .X = Framer * FireEmblemUnit.UnitSize.Width : .Width = FireEmblemUnit.UnitSize.Width
                .Y = 0 : .Height = FireEmblemUnit.UnitSize.Height
            End With
            Grafikengine.szfScale = FireEmblemUnit.UnitSize
        Else
            With Grafikengine.recBild
                .X = Framer * Hauptmenue.Feldbreite : .Width = Hauptmenue.Feldbreite
                .Y = 0 : .Height = Hauptmenue.Feldbreite
            End With
            Grafikengine.szfScale = New Size(Hauptmenue.Feldbreite, Hauptmenue.Feldbreite)
        End If
        ObjektEinheit.Malen(Spieler, Framer, Unit, Farbe)

        Text.Malen(Grafikengine.ptfPosition)
        Framer = 1
    End Sub

    Public Overloads Overrides Function MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) As Boolean

    End Function
End Class